package com.huan.study.mybatis.handler;

import com.huan.study.mybatis.util.AESUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author YanXxx
 * @date 2022-11-03 18:03
 */
@Slf4j
@Component("aesDecryptImpl")
public class AESDecryptImpl implements DecryptHandler {

    @Value("${aes.key}")
    private String key;

    /**
     * 解密
     *
     * @param decryptValue 解密值
     * @return 解密后的值
     */
    @Override
    public String decryptMethod(String decryptValue) {
        log.info("AES解密");
        if (decryptValue.startsWith(AESUtil.KEY_SENSITIVE)) {
            decryptValue = decryptValue.substring(10);
            return AESUtil.decrypt(decryptValue, key);
        }
        return decryptValue;
    }
}
